package core;

import core.field.Field;
import core.field.Fleet;
import core.field.LaborCamp;
import core.field.Refuge;
import core.field.StartField;
import core.field.Tax;
import core.field.Territory;


public class GameBoard {

	private Field[] fields = new Field[22];
	
	public GameBoard(){
		fields[0] = new StartField();
		fields[1] = new Territory("Tribe Encampment", 100, 1000);	//.setDescription("Tribe Encampment: If another player owns this field, pay 100 to them when you land here");
		fields[2] = new Territory("Crater", 300, 1500);				//.setDescription("Crater: If another player owns this field, pay 300 to them when you land here");
		fields[3] = new Territory("Mountain", 500, 2000);			//.setDescription("Mountain: If another player owns this field, pay 500 to them when you land here");
		fields[4] = new Territory("Cold Desert", 700, 3000);		//.setDescription("Cold Desert: If another player owns this field, pay 700 to them when you land here");
		fields[5] = new Territory("Black cave", 1000, 4000);		//.setDescription("Black cave: If another player owns this field, pay 1000 to them when you land here");
		fields[6] = new Territory("The WereWall", 1300, 4300);		//.setDescription("The WereWall: If another player owns this field, pay 1300 to them when you land here");
		fields[7] = new Territory("Mountain village", 1600, 4750);	//.setDescription("Mountain village: If another player owns this field, pay 1600 to them when you land here");
		fields[8] = new Territory("South Citadel", 2000, 5000);		//.setDescription("South Citadel: If another player owns this field, pay 2000 to them when you land here");
		fields[9] = new Territory("Palace gates", 2600, 5500);		//.setDescription("Palace gates: If another player owns this field, pay 2600 to them when you land here");
		fields[10] = new Territory("Tower", 3200, 6000);			//.setDescription("Tower: If another player owns this field, pay 3200 to them when you land here");
		fields[11] = new Territory("Castle", 4000, 8000);			//.setDescription("Castle: If another player owns this field, pay 4000 to them when you land here");
		fields[12] = new Refuge("Walled city", 5000);				//.setDescription("Walled city: Congratulations! For landing here you are rewarded 5000!");
		fields[13] = new Refuge("Monastery", 500);					//.setDescription("Monastery: Congratulations! For landing here you are rewarded 500!");
		fields[14] = new LaborCamp("Huts in the mountain", 2500);	//.setDescription("Huts in the mountain: If another player owns this field, pay 100 x [DiceSum] x [LaborsOwned]");
		fields[15] = new LaborCamp("The pit", 2500);				//.setDescription("The pit: If another player owns this field, pay 100 x [DiceSum] x [LaborsOwned]");
		fields[16] = new Tax("Goldmine", 2000);						//.setDescription("Goldmine: Taxes are here... Pay up! You lose 2000 upon landing on this field.");
		fields[17] = new Tax("Caravan", 4000);						//.setDescription("Caravan: Taxes are here... Pay up! You lose 4000 or 10% of total assets upon landing on this field.");
		fields[18] = new Fleet("Second Sail");						//.setPrice(4000).setDescription("Second Sail");
		fields[19] = new Fleet("Sea Groover");						//.setPrice(4000).setDescription("Sea Groover");
		fields[20] = new Fleet("the Buccaneers");					//.setPrice(4000).setDescription("the Buccaneers");
		fields[21] = new Fleet("Privateer armade");					//.setPrice(4000).setDescription("Privateer armade");
		
		fields[0].setDescription("You start here!");
		fields[1].setDescription("Tribe Encampment: If another player owns this field, pay 100 to them when you land here");
		fields[2].setDescription("Crater: If another player owns this field, pay 300 to them when you land here");
		fields[3].setDescription("Mountain: If another player owns this field, pay 500 to them when you land here");
		fields[4].setDescription("Cold Desert: If another player owns this field, pay 700 to them when you land here");
		fields[5].setDescription("Black cave: If another player owns this field, pay 1000 to them when you land here");
		fields[6].setDescription("The WereWall: If another player owns this field, pay 1300 to them when you land here");
		fields[7].setDescription("Mountain village: If another player owns this field, pay 1600 to them when you land here");
		fields[8].setDescription("South Citadel: If another player owns this field, pay 2000 to them when you land here");
		fields[9].setDescription("Palace gates: If another player owns this field, pay 2600 to them when you land here");
		fields[10].setDescription("Tower: If another player owns this field, pay 3200 to them when you land here");
		fields[11].setDescription("Castle: If another player owns this field, pay 4000 to them when you land here");
		fields[12].setDescription("Walled city: Congratulations! For landing here you are rewarded 5000!");
		fields[13].setDescription("Monastery: Congratulations! For landing here you are rewarded 500!");
		fields[14].setDescription("Huts in the mountain: If another player owns this field, pay 100 x [DiceSum] x [LaborsOwned]");
		fields[15].setDescription("The pit: If another player owns this field, pay 100 x [DiceSum] x [LaborsOwned]");
		fields[16].setDescription("Goldmine: Taxes are here... Pay up! You lose 2000 upon landing on this field.");
		fields[17].setDescription("Caravan: Taxes are here... Pay up! You lose 4000 or 10% of total assets upon landing on this field.");
		fields[18].setDescription("Second Sail: If another player owns this field, pay 500 (1000 if he owns 2, 2000 if 3, and 4000 if 4)");
		fields[19].setDescription("Sea Groover: If another player owns this field, pay 500 (1000 if he owns 2, 2000 if 3, and 4000 if 4)");
		fields[20].setDescription("the Buccaneers: If another player owns this field, pay 500 (1000 if he owns 2, 2000 if 3, and 4000 if 4)");
		fields[21].setDescription("Privateer armade: If another player owns this field, pay 500 (1000 if he owns 2, 2000 if 3, and 4000 if 4)");
		
		
		scrambleBoard();
	}
	
	public Field[] getFields(){
		return fields;
	}
	
	public int getIndexOf(String name){
		int i = -1;
		for(Field f : fields){
			i++;
			if(f.getName().equals(name))
				return i;
		}
		return i;
	}
	
	private void scrambleBoard(){
		Field[] temp = new Field[fields.length];
		temp[0] = fields[0];
		for(int i=1; i<temp.length;i++){
			int rnd = (int)(Math.random()*temp.length);
			while(temp[rnd] != null){
				rnd = (int)(Math.random()*temp.length);
			}
			temp[rnd]=fields[i];
		}
		fields = temp;
	}
	
	public desktop_fields.Field[] getFieldsGUI(){
		desktop_fields.Field[] temp = new desktop_fields.Field[this.fields.length];
		
		for(int i = 0; i<temp.length; i++){
			if(fields[i].getClass().equals(new Territory().getClass()))
				temp[i] = new desktop_fields.Street.Builder().build();
			else if(fields[i].getClass().equals(new StartField().getClass()))
				temp[i] = new desktop_fields.Start.Builder().build();
			else if(fields[i].getClass().equals(new Refuge().getClass()))
				temp[i] = new desktop_fields.Refuge.Builder().build();
			else if(fields[i].getClass().equals(new LaborCamp().getClass()))
				temp[i] = new desktop_fields.Brewery.Builder().build();
			else if(fields[i].getClass().equals(new Tax().getClass()))
				temp[i] = new desktop_fields.Tax.Builder().build();
			else if(fields[i].getClass().equals(new Fleet().getClass()))
				temp[i] = new desktop_fields.Shipping.Builder().build();
			// temp[i] = new desktop_fields.
			
			temp[i].setTitle(fields[i].getName());
			temp[i].setSubText(fields[i].subText());
			temp[i].setDescription(fields[i].getDescription());
		}
		
		return temp;
	}
}
